# _*_ encoding:utf-8 _*_
from game.models import UserRecord, PlatformRecord
from game.serializers import UserRecordSerializer, PlatformRecordSerializer
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ViewSetMixin
from utils.auth import LuffyAuth
from utils.pagefenye import RecordPagination

class UserRecordlist(ViewSetMixin,APIView):
   # authentication_classes = [LuffyAuth,]
    pg = RecordPagination()

    '''获取平台全部记录'''
    def list(self,request,*args,**kwargs):

        ret = {'code':1000,'data':None}
        try:
            queryset = PlatformRecord.objects.all()
            page_roles = self.pg.paginate_queryset(queryset=queryset, request=request, view=self)

            ser = PlatformRecordSerializer(instance=page_roles,many=True)
            ret['data'] = ser.data
        except Exception as e:
            ret['code'] = 1001
            ret['error'] = '获取平台开奖记录失败'

        return Response(ret)

    def list1(self,request,*args,**kwargs):
        '''获取个人全部记录'''
        ret = {'code':1000,'data':None}
        try:
            queryset = UserRecord.objects.all()
            page_UserRecord = self.pg.paginate_queryset(queryset=queryset, request=request, view=self)
            ser = UserRecordSerializer(instance=page_UserRecord,many=True)
            ret['data'] = ser.data
        except Exception as e:
            ret['code'] = 1001
            ret['error'] = '获取个人全部记录失败'

        return Response(ret)

    def retrieve(self,request,*args,**kwargs):
        '''用户记录详记录'''
        ret = {'code': 1000, 'data': None}
        try:
            # 用户ID=2
            pk = kwargs.get('pk')
            # 用户记录详细对象
            obj = UserRecord.objects.filter(uid=pk)[0]
            ser = UserRecordSerializer(instance=obj,many=False)
            ret['data'] = ser.data

        except Exception as e:
            ret['code'] = 1001
            ret['error'] = '获取个人详细记录失败'
        return Response(ret)

